package com.my.admin.api;

import com.my.admin.entity.LeaveComment;
import com.my.admin.service.LeaveCommentService;
import com.my.admin.util.Rest;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "留言接口", tags = "留言接口")
@RestController
@RequestMapping("api")
@CrossOrigin
public class LeaveCommentApiController {

    @Autowired
    private LeaveCommentService service;

    @GetMapping("leaveComment")
    public Rest get() {
        return Rest.ok().setData("leaveComments", service.list());
    }

    @PostMapping("leaveComment")
    public Rest add(@RequestBody LeaveComment leaveComment) {
        if(service.save(leaveComment)) {
            return Rest.ok("留言成功！");
        }
        return Rest.err("留言失败！  ");
    }

}
